package com.cxj.lejia;

import com.waps.AppConnect;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

public class DetailActivity extends Activity {
    public static final Integer[] buttionTextIds = { R.string.red_button1,
            R.string.red_button2, R.string.blue_button1, R.string.blue_button2,
            R.string.yellow_button1, R.string.yellow_button2,
            R.string.green_button1, R.string.green_button2 };

    public static final Integer[] buttionImgIds = { R.drawable.redheart,
            R.drawable.blueheart, R.drawable.yellowheart, R.drawable.greenheart };
   
    private Button returnButton;

	private Button owns;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail);

        Bundle bundle = getIntent().getExtras();
       
        String redinfo = "<font color='red'>红色:<big>"+bundle.getInt("red")+"</big></font>";
        String blueinfo = "<font color='blue'>蓝色:<big>"+bundle.getInt("blue")+"</big></font>";
        String yellowinfo = "<font color='yellow'>黄色:<big>"+bundle.getInt("yellow")+"</big></font>";
        String greeninfo = "<font color='green'>绿色:<big>"+bundle.getInt("green")+"</big></font>";
       
        Spanned text = Html.fromHtml("最终性格色彩结果:" + redinfo + " " + blueinfo + " " + yellowinfo + " " + greeninfo);
        TextView textView = (TextView) findViewById(R.id.result_textview);
        textView.setText(text);
        
        GridView gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(new ButtonAdapter());

		if (!MainActivity.hasEnoughRequrePoint) {// 没达到积分
			MainActivity.showDialog(DetailActivity.this);
		}

        returnButton = (Button) findViewById(R.id.return_Button);

        returnButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View arg0) {
                finish();
            }
        });
        
		owns = (Button) findViewById(R.id.OwnsButton);
		owns.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View arg0) {
				// 显示自家应用列表.
				AppConnect.getInstance(DetailActivity.this).showMore(DetailActivity.this);
			}
		});
    }

    private class ButtonAdapter extends ArrayAdapter<String> {
        ButtonAdapter() {
            super(DetailActivity.this, R.layout.button, new String[8]);
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater infalter = getLayoutInflater();
            View row = infalter.inflate(R.layout.button, parent, false);
            Button cb = (Button) row.findViewById(R.id.color_button);

            final int idx = position;
            cb.setText(buttionTextIds[idx]);
            cb.setBackgroundResource(buttionImgIds[idx / 2]);
            cb.setOnClickListener(new Button.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(DetailActivity.this, DescActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("index", idx);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
            return row;
        }
    }
}
